package com.myzhouye.biz.service;/***
 *                    _ooOoo_
 *                   o8888888o
 *                   88" . "88
 *                   (| -_- |)
 *                    O\ = /O
 *                ____/`---'\____
 *              .   ' \\| |// `.
 *               / \\||| : |||// \
 *             / _||||| -:- |||||- \
 *               | | \\\ - /// | |
 *             | \_| ''\---/'' | |
 *              \ .-\__ `-` ___/-. /
 *           ___`. .' /--.--\ `. . __
 *        ."" '< `.___\_<|>_/___.' >'"".
 *       | | : `- \`.;`\ _ /`;.`/ - ` : | |
 *         \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 *                    `=---='
 *
 * .............................................
 *          佛祖保佑             永无BUG
 */

import com.myzhouye.biz.dto.BaseWarehouse;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @program: game01
 * @description: 仓库业务逻辑
 * @author: 那条蠢鱼
 * @create: 2025-09-30 10:32
 **/
@Service
@Slf4j
public class WarehouseService {

    private final BaseWarehouse warehouse = new BaseWarehouse();

    @PostConstruct
    public void initWarehouse() {
        warehouse.setCapacity(0);
        warehouse.setSize(0);
        warehouse.setItems(new HashMap<>());
    }

    public BaseWarehouse getWarehouse() {
        return warehouse;
    }


    public void createWarehouse() {
        //增加1个仓库，仓库数量+1,容量+200
        warehouse.setSize(warehouse.getSize() + 1);
        warehouse.setCapacity(warehouse.getCapacity() + 200);
    }

    public void append(String key,Integer nums){
        //按照key增加nums的数量
        warehouse.getItems().put(key,warehouse.getItems().getOrDefault(key,0)+nums);
    }
}
